using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.IO;

namespace SBPweb.Modules.Modularity
{
	/// <summary>
	/// Class of ModuleProfile
	/// </summary>
	public class ModuleProfile : ConfigurationSection
	{
		#region Constructor logic

		/// <summary>
		/// Initializes a new ModuleProfile instance
		/// </summary>
		internal ModuleProfile()
		{
		}

        public static ModuleProfile CreateInstance(FileInfo fileInfo)
        {
            Configuration conf = ConfigurationManager.OpenExeConfiguration(fileInfo.FullName);
            return (ModuleProfile)conf.Sections.Get("moduleProfile");
        }

		#endregion

		#region Public properties

		/// <summary>
		/// Gets or sets the Type Name of the module
		/// </summary>
		[ConfigurationProperty("typeName", IsRequired = true)]
		public String TypeName
		{
			get
			{
				return (String)this["typeName"];
			}
			set
			{
				this["typeName"] = value;
			}
		}

        /// <summary>
        /// Gets or sets the version of the module
        /// </summary>
        [ConfigurationProperty("version", IsRequired = true)]
        public String ConfigurationVersion
		{
			get
			{
				return (String)this["version"];
			}
			set
			{
				this["version"] = value;
			}
		}

		/// <summary>
		/// Gets or sets true if module is CoreModule
		/// </summary>
		[ConfigurationProperty("isCoreModule", DefaultValue = false, IsRequired = true)]
		public bool IsCoreModule
		{
			get
			{
				return (bool)this["isCoreModule"];
			}
			set
			{
				this["isCoreModule"] = value;
			}
		}

		/// <summary>
		/// Gets or sets a KeyValueConfigurationCollection that describes the module groups uses the module
		/// Key is the name of the module group
		/// Value is "Required" if module is required and auto load on the module group
		/// Value is "Available" if module is only available on the module group
		/// </summary>
		[ConfigurationProperty("moduleGroups")]
		public KeyValueConfigurationCollection ModuleGroups
		{
			get
			{
				return (KeyValueConfigurationCollection)this["moduleGroups"];
			}
			set
			{
				this["moduleGroups"] = value;
			}
		}

		/// <summary>
		/// Gets or sets a KeyValueConfigurationCollection that describes the module version dependencies
		/// Key is the name of the module
		/// Value is a version mask.
		/// Version mask examples:
		/// "1.0.*" - versions starting with 1.0
		/// "1.*" - versions starting with 1
		/// "1.*.0.1" - versions starting with 1 and ending with 0.1
		/// "1.0.0.1-1.1.0.0" - versions from 1.0.0.1 to 1.1.0.0
		/// "1.0.0.1-" - versions above 1.0.0.1
		/// "-1.0.0.1" - version below 1.0.0.1
		/// </summary>
        [ConfigurationProperty("moduleVersionDependencies")]
        public KeyValueConfigurationCollection ModuleVersionDependencies
        {
            get
            {
				return (KeyValueConfigurationCollection)this["moduleVersionDependencies"];
            }
            set
            {
				this["moduleVersionDependencies"] = value;
            }
        }

		/// <summary>
		/// Gets or sets a KeyValueConfigurationCollection that describes the assembly version dependencies
		/// Key is the name of assembly file (.dll)
		/// Value is a version mask.
		/// Version mask examples:
		/// "1.0.*" - versions starting with 1.0
		/// "1.*" - versions starting with 1
		/// "1.*.0.1" - versions starting with 1 and ending with 0.1
		/// "1.0.0.1-1.1.0.0" - versions from 1.0.0.1 to 1.1.0.0
		/// "1.0.0.1-" - versions above 1.0.0.1
		/// "-1.0.0.1" - version below 1.0.0.1
		/// </summary>
		[ConfigurationProperty("assemblyVersionDependencies")]
        public KeyValueConfigurationCollection AssemblyVersionDependencies
        {
            get
            {
				return (KeyValueConfigurationCollection)this["assemblyVersionDependencies"];
            }
            set
            {
				this["assemblyVersionDependencies"] = value;
            }
        }

		/// <summary>
		/// Gets or sets a KeyValueConfigurationCollection that describes the supported cultures of the module
		/// Key is the code of the culture (like: "en-US", "hu-HU") or "*" for modules without UI
		/// Value: don't care
		/// </summary>
		[ConfigurationProperty("supportedCultures")]
		public KeyValueConfigurationCollection SupportedCultures
		{
			get
			{
				return (KeyValueConfigurationCollection)this["supportedCultures"];
			}
			set
			{
				this["supportedCultures"] = value;
			}
		}

		#endregion
	}
}
